import http from '@/http/api.js'

// 获取token
const token = (tenantId, username, password, type) => {
	return http.request({		 
		//#ifndef H5
		url: '/blade-auth/oauth/token',
		//#endif
		//#ifdef H5
		url: '/api/blade-auth/oauth/token',
		//#endif
		method: 'POST',
		header: { 
			'tenant-id': tenantId,
			'Authorization':'Basic d3hhcHA6d3hhcHBfc2VjcmV0'
		},
		params: {
			tenantId,
			username,
			password,
			grant_type: "password",
			scope: "all",
			type
		}
	})
}

const refreshToken = (refresh_token, tenantId) => {
	return http.request({		 
		//#ifndef H5
		url: '/blade-auth/oauth/token',
		//#endif
		//#ifdef H5
		url: '/api/blade-auth/oauth/token',
		//#endif
		method: 'post',
		headers: {
			'tenant-id': tenantId,
			'Authorization':'Basic d3hhcHA6d3hhcHBfc2VjcmV0'
		},
		params: {
			tenantId,
			refresh_token,
			grant_type: "refresh_token",
			scope: "all",
		}
	})
}

// 获取用户信息
const userInfo = () => {
	return http.request({
		url: '/api/blade-system/user/info',
		method: 'GET',
	})
}

// 获取用户信息
export const getUser = (id) => {
	return http.request({
		url: '/api/blade-system/user/detail',
		method: 'GET',
		params: { id }
	})
}
 
export const sendCode = (params) => {
 	return http.request({		 
 		//#ifndef H5
 		url: '/xrsk-server/login/sendCode',
 		//#endif
 		//#ifdef H5
 		url: '/api/xrsk-server/login/sendCode',
 		//#endif
 		method: 'GET',
 		params
 	})
}

export const register =(tenantId, params) => {
 	return http.request({		 
 		//#ifndef H5
 		url: '/xrsk-server/login/register',
 		//#endif
 		//#ifdef H5
 		url: '/api/xrsk-server/login/register',
 		//#endif
 		method: 'POST',
 		header: { 
 			'tenant-id': tenantId,
 			'Authorization':'Basic d3hhcHA6d3hhcHBfc2VjcmV0'
 		},
 		data:params
 	})
}
    
export default {
	token,
	userInfo,
	refreshToken,
	sendCode,
	register
	
}
